﻿CREATE FUNCTION [dbo].[fn_PrimaryKeyColumnList]
(
	@Table sysname
)
RETURNS VARCHAR(MAX)
AS
BEGIN
	DECLARE @ColumnList VARCHAR(MAX)
	
	SELECT @ColumnList = COALESCE(@ColumnList + ',', '') + ColumnName
	FROM   dbo.fn_PrimaryKeyColumns(@Table)
	
	RETURN @ColumnList
END